home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_cyrus-sasl.idb / usr / freeware / include / saslutil.h.z / saslutil.h
C/C++ Source or Header  |  2001-07-06  |  3KB  |  85 lines

  1. /* saslutil.h -- various utility functions in SASL library
  2.  */
  3. /*234567890123456789012345678901234567890123456789012345678901234567890123456*/
  4.  
  5. #ifndef SASLUTIL_H
  6. #define SASLUTIL_H 1
  7.  
  8. #include "sasl.h"
  9.  
  10. /* base64 decode
  11.  *  in     -- input data
  12.  *  inlen  -- length of input data
  13.  *  out    -- output data (may be same as in, must have enough space)
  14.  * result:
  15.  *  outlen -- actual output length
  16.  *
  17.  * returns SASL_BADPROT on bad base64, SASL_OK on success
  18.  */
  19. LIBSASL_API int sasl_decode64(const char *in, unsigned inlen,
  20.                   char *out, unsigned *outlen);
  21.  
  22. /* base64 encode
  23.  *  in      -- input data
  24.  *  inlen   -- input data length
  25.  *  out     -- output buffer (will be NUL terminated)
  26.  *  outmax  -- max size of output buffer
  27.  * result:
  28.  *  outlen  -- gets actual length of output buffer (optional)
  29.  * 
  30.  * Returns SASL_OK on success, SASL_BUFOVER if result won't fit
  31.  */
  32. LIBSASL_API int sasl_encode64(const char *in, unsigned inlen,
  33.                   char *out, unsigned outmax, unsigned *outlen);
  34.  
  35. /* make a challenge string (NUL terminated)
  36.  *  buf      -- buffer for result
  37.  *  maxlen   -- max length of result
  38.  *  hostflag -- 0 = don't include hostname, 1 = include hostname
  39.  * returns final length or 0 if not enough space
  40.  */
  41. LIBSASL_API int sasl_mkchal(sasl_conn_t *conn, char *buf,
  42.                 unsigned maxlen, int hostflag);
  43.  
  44. /* verify a string is valid UTF-8
  45.  *  if len == 0, strlen(str) will be used.
  46.  * returns SASL_BADPROT on error, SASL_OK on success
  47.  */
  48. LIBSASL_API int sasl_utf8verify(const char *str, unsigned len);
  49.  
  50. /* create random pool seeded with OS-based params
  51.  */
  52. LIBSASL_API int sasl_randcreate(sasl_rand_t **rpool);
  53.  
  54. /* free random pool from randcreate
  55.  */
  56. LIBSASL_API void sasl_randfree(sasl_rand_t **rpool);
  57.  
  58. /* seed random number generator
  59.  */
  60. LIBSASL_API void sasl_randseed(sasl_rand_t *rpool,
  61.                    const char *seed,
  62.                    unsigned len);
  63.  
  64. /* generate "random" octets. in reality, these should ONLY be used for
  65.  * nonces, where it's important that a nonce be unique (with high
  66.  * probability) but not necessary cryptographically random. 
  67.  *
  68.  * an interesting thing to think about is forking, causing the pool to be
  69.  * reused. */
  70. LIBSASL_API void sasl_rand(sasl_rand_t *rpool,
  71.                char *buf,
  72.                unsigned len);
  73.  
  74. /* churn data into random number generator
  75.  */
  76. LIBSASL_API void sasl_churn(sasl_rand_t *rpool, 
  77.                 const char *data,
  78.                 unsigned len);
  79. #ifdef WIN32
  80. LIBSASL_API int getopt(int argc, char **argv, char *optstring);
  81. LIBSASL_API char * getpass(const char *prompt);
  82. #endif /* WIN32 */
  83.  
  84. #endif /* SASLUTIL_H */
  85.